package com.tms.project.tms.train.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.tms.framework.aspectj.lang.annotation.Log;
import com.tms.framework.aspectj.lang.enums.BusinessType;
import com.tms.project.tms.train.domain.TeacherTrain;
import com.tms.project.tms.train.service.ITeacherTrainService;
import com.tms.framework.web.controller.BaseController;
import com.tms.framework.web.domain.AjaxResult;
import com.tms.common.utils.poi.ExcelUtil;
import com.tms.framework.web.page.TableDataInfo;

/**
 * 教师培训信息Controller
 *
 * @author xyl
 * @date 2021-03-23
 */
@Controller
@RequestMapping("/tms/train")
public class TeacherTrainController extends BaseController {
    private String prefix = "tms/train";

    @Autowired
    private ITeacherTrainService teacherTrainService;

    @RequiresPermissions("tms:train:view")
    @GetMapping()
    public String train() {
        return prefix + "/train";
    }

    /**
     * 查询教师培训信息列表
     */
    @RequiresPermissions("tms:train:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TeacherTrain teacherTrain) {
        startPage();
        List<TeacherTrain> list = teacherTrainService.selectTeacherTrainList(teacherTrain);
        return getDataTable(list);
    }

    /**
     * 导出教师培训信息列表
     */
    @RequiresPermissions("tms:train:export")
    @Log(title = "教师培训信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TeacherTrain teacherTrain) {
        List<TeacherTrain> list = teacherTrainService.selectTeacherTrainList(teacherTrain);
        ExcelUtil<TeacherTrain> util = new ExcelUtil<TeacherTrain>(TeacherTrain.class);
        return util.exportExcel(list, "train");
    }

    /**
     * 新增教师培训信息
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存教师培训信息
     */
    @RequiresPermissions("tms:train:add")
    @Log(title = "教师培训信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TeacherTrain teacherTrain) {
        return toAjax(teacherTrainService.insertTeacherTrain(teacherTrain));
    }

    /**
     * 修改教师培训信息
     */
    @GetMapping("/edit/{trainId}")
    public String edit(@PathVariable("trainId") Long trainId, ModelMap mmap) {
        TeacherTrain teacherTrain = teacherTrainService.selectTeacherTrainById(trainId);
        mmap.put("teacherTrain", teacherTrain);
        return prefix + "/edit";
    }

    /**
     * 修改保存教师培训信息
     */
    @RequiresPermissions("tms:train:edit")
    @Log(title = "教师培训信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TeacherTrain teacherTrain) {
        return toAjax(teacherTrainService.updateTeacherTrain(teacherTrain));
    }

    /**
     * 删除教师培训信息
     */
    @RequiresPermissions("tms:train:remove")
    @Log(title = "教师培训信息", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(teacherTrainService.deleteTeacherTrainByIds(ids));
    }
}
